package moni.anyou.com.view.view;
import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.scu.miomin.shswiperefresh.core.SHSwipeRefreshLayout;
import com.yancy.gallerypick.utils.SystemBarTintManager;
import org.json.JSONArray;
import org.json.JSONObject;
import org.kymjs.aframe.http.KJHttp;
import org.kymjs.aframe.http.KJStringParams;
import org.kymjs.aframe.http.StringCallBack;
import java.util.ArrayList;
import java.util.List;
import moni.anyou.com.view.R;
import moni.anyou.com.view.base.BaseFragment;
import moni.anyou.com.view.bean.request.ReqDynamicsCommentBean;
import moni.anyou.com.view.bean.request.ReqSentDynamicsBean;
import moni.anyou.com.view.bean.request.ReqsLikeTeacherBean;
import moni.anyou.com.view.bean.response.ResDynamicsBean;
import moni.anyou.com.view.bean.response.ResHomeData;
import moni.anyou.com.view.config.SysConfig;
import moni.anyou.com.view.tool.AppTools;
import moni.anyou.com.view.tool.KeyBoardTools;
import moni.anyou.com.view.tool.ToastTools;
import moni.anyou.com.view.view.PageFragment;
import moni.anyou.com.view.view.adapter.IndexDynamicsItemsAdapter;
import moni.anyou.com.view.view.dynamics.adapter.DynamicsItemsAdapter;
import moni.anyou.com.view.view.kindergarten.adapter.adpater.RecyclerViewAdapter;
import moni.anyou.com.view.view.my.SystemsNoticeActivity;
import moni.anyou.com.view.widget.NetProgressWindowDialog;
import moni.anyou.com.view.widget.banner.AutoScrollViewPager;
import moni.anyou.com.view.widget.dialog.PopCommentSent;
import moni.anyou.com.view.widget.utils.imageload.ImageLoadUtil;


public class KindergartenFragment extends BaseFragment implements View.OnClickListener{
    private AutoScrollViewPager bannerView;
    private View mView;
    private LinearLayout mTextLayout;
    private PopCommentSent mPopCommentSent;
    private TextView tv_more;
    private ImageView ivEmail;
    private IndexDynamicsItemsAdapter mIndexDynamicsItemsAdapter;
    private NetProgressWindowDialog window;
    private RecyclerView lv_dynamics;
    private ViewPager viewPager;
    private LinearLayout llBanner2;
    private LinearLayout llList;
   // private SHSwipeRefreshLayout swipeRefreshLayout;
    //private LinearLayout llMessage;

    private static class PagerAdapter extends FragmentPagerAdapter {


        private final List<String> images;

        private PagerAdapter(FragmentManager fragmentManager, List<String> images) {
            super(fragmentManager);
            this.images = images;
        }

        @Override
        public int getCount() {
            return images.size();
        }

        @Override
        public Fragment getItem(int position) {
            return PageFragment.newInstance(images.get(position));
        }
    }

    private void initState() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

    }

    private SystemBarTintManager tintManager;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_kindergarten, container, false);
        //List<String> images= new ArrayList<>();
        // images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1537665927180&di=d85120ed895b5b4c8845faf8784b198e&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F0117e2571b8b246ac72538120dd8a4.jpg%401280w_1l_2o_100sh.jpg");
        //images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1537665948204&di=470b41433ac86763e36d9fd4055a1a74&imgtype=0&src=http%3A%2F%2Fpic2.52pk.com%2Ffiles%2F160216%2F5329500_160443_1.png");
        //images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1537665985091&di=7177e9451dd9c586fc125e9220848747&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01f09e577b85450000012e7e182cf0.jpg%401280w_1l_2o_100sh.jpg");
        // images.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1537666021567&di=da28e4c88f3ab963ed422a2f9cbbc6ab&imgtype=0&src=http%3A%2F%2Fimg12.3lian.com%2Fgaoqing02%2F01%2F58%2F85.jpg");
        mPopCommentSent = new PopCommentSent(mBaseActivity, this);
        viewPager = (ViewPager) mView.findViewById(R.id.view_pager);
        llBanner2 = (LinearLayout) mView.findViewById(R.id.ll_banner2);
        llList = (LinearLayout) mView.findViewById(R.id.ll_list);
       // llMessage = (LinearLayout) mView.findViewById(R.id.ll_message);

        mIndexDynamicsItemsAdapter = new IndexDynamicsItemsAdapter(this);
        lv_dynamics = (RecyclerView) mView.findViewById(R.id.lv_dynamics);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        lv_dynamics.setLayoutManager(linearLayoutManager);

        lv_dynamics.setAdapter(mIndexDynamicsItemsAdapter);

        init(mView);
        //initSwipeRefreshLayout();
        return mView;
    }




    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_more:
                Intent i = new Intent();
                i.setClass(mBaseActivity, LeaderDetailActivity.class);
                mBaseActivity.startActivity(i);
                activityAnimation(RIGHT_IN);
                break;
            case R.id.iv_email:
                Intent i2 = new Intent();
                i2.setClass(mBaseActivity,SystemsNoticeActivity.class);
                startActivity(i2);
                break;
            case R.id.btn_pop_sent:
                postAddCommentDynamics(mPopCommentSent.data, mPopCommentSent.position);

                KeyBoardTools.closeKeybord(mPopCommentSent.etComments, mContext);
                mPopCommentSent.backgroundAlpha(1f);
                mPopCommentSent.dismiss();
                break;
            default:
                break;
        }
    }
    private void initViewPager(JSONArray jsonArr) {
        try {
            if (jsonArr.length() > 0) {
                List<String> images = new ArrayList<>();
                for (int i = 0; i < jsonArr.length(); i++) {
                    images.add(SysConfig.PicUrl + jsonArr.getJSONObject(i).getString("adInfoPic"));
                }
                viewPager.setAdapter(new PagerAdapter(getActivity().getSupportFragmentManager(), images));
            }
        } catch (Exception ex) {

        }
    }

    private void initRecommendRoute(JSONArray jsonArr) {
        try {
            llBanner2.removeAllViews();
            for (int i = 0; i < jsonArr.length(); i++) {
                addBanner2(jsonArr.getJSONObject(i));
            }
        }
        catch(Exception ex){

        }

    }
    private void initRecommendTeam(JSONArray jsonArr) {
        try {
            llList.removeAllViews();
            for (int i = 0; i < jsonArr.length(); i++) {
                addList(jsonArr.getJSONObject(i));
            }
        }
        catch(Exception ex){

        }

    }
    /*
    private void initRecommendArticle(JSONArray jsonArr) {
        try {
            llMessage.removeAllViews();
            for (int i = 0; i < jsonArr.length(); i++) {
                addMessage(jsonArr.getJSONObject(i));
            }
        }
        catch(Exception ex){

        }

    }
    */




    private void addList(final  JSONObject jsonObject) {
        //动态添加
        try {
            View layout = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_mark_main_page2_item, null);
            ImageView team_pic = layout.findViewById(R.id.iv_teampic);
            TextView tv_member_num = (TextView) layout.findViewById(R.id.tv_member_num);
            tv_member_num.setText("成员:"+jsonObject.getString("memberNumber")+"人");
            TextView tv_teamname = (TextView) layout.findViewById(R.id.tv_teamname);
            tv_teamname.setText(jsonObject.getString("teamName"));
            TextView tv_startTime = (TextView) layout.findViewById(R.id.tv_startTime);
            tv_startTime.setText("时间:"+jsonObject.getString("startTime")+"到"+jsonObject.getString("endTime"));
            TextView tv_routename = (TextView) layout.findViewById(R.id.tv_routename);
            tv_routename.setText(jsonObject.getString("routeName"));
            TextView tv_teamleader = (TextView) layout.findViewById(R.id.tv_teamleader);
            tv_teamleader.setText("领队:"+jsonObject.getString("nick"));
            TextView tv_join = (TextView) layout.findViewById(R.id.tv_join);
            if (jsonObject.getInt("isjoin") == 1){
                tv_join.setVisibility(View.INVISIBLE);
            }
            tv_join.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        postJoinTeam(jsonObject.getString("teamID"));
                    }
                    catch(Exception ex){

                    }
                }
            });
            ImageLoader imageLoader = ImageLoadUtil.getInstance(getActivity()).mImageLoader;
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .cacheInMemory(true)
                    .cacheOnDisk(true)
                    .considerExifParams(true)
                    .bitmapConfig(Bitmap.Config.RGB_565)
                    .considerExifParams(true)
                    .delayBeforeLoading(0)
                    .resetViewBeforeLoading(true)
                    .displayer(new RoundedBitmapDisplayer(0))
                    .displayer(new FadeInBitmapDisplayer(0))
                    .build();
            imageLoader.displayImage(SysConfig.PicUrl+jsonObject.getString("teamPic"),team_pic,options);
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        Intent intent = new Intent();
                        //intent.putExtra("routeID", jsonObject.getString("routeID"));
                        intent.setClass(getContext(), LeaderDetailActivity.class);
                        getActivity().startActivity(intent);
                    }
                    catch(Exception ex){

                    }
                }
            });
            llList.addView(layout);
        }
        catch(Exception ex){
            Toast.makeText(mContext, ex.toString(), Toast.LENGTH_LONG).show();
        }
    }

    //为第二个banner添加视图
    public void addBanner2(final JSONObject jsonObject){
        try {
            View layout = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_mark_main_page1_item, null);
            //文字
            TextView yellowText = layout.findViewById(R.id.yellow_text);
            yellowText.setText(jsonObject.getString("teamCount")+"个团");
            TextView tv_address = (TextView) layout.findViewById(R.id.tv_address);
            tv_address.setText(jsonObject.getString("routeName"));
            TextView tv_name = (TextView) layout.findViewById(R.id.tv_name);
            tv_name.setText(jsonObject.getString("routeInfo"));
            ImageView iv_bg = layout.findViewById(R.id.iv_bg);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                iv_bg.setBackground(null);
            }
            iv_bg.setImageBitmap(null);
           // ImageLoader imageLoader = ImageLoadUtil.getInstance(getActivity()).mImageLoader;
            //imageLoader.displayImage(SysConfig.PicUrl+jsonObject.getString("pic"), iv_bg);
            ImageLoader imageLoader = ImageLoadUtil.getInstance(getActivity()).mImageLoader;
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .cacheInMemory(true)
                    .cacheOnDisk(true)
                    .considerExifParams(true)
                    .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                    .bitmapConfig(Bitmap.Config.RGB_565)
                    .considerExifParams(true)
                    .delayBeforeLoading(0)
                    .resetViewBeforeLoading(true)
                    .displayer(new RoundedBitmapDisplayer(0))
                    .displayer(new FadeInBitmapDisplayer(0))
                    .build();
            imageLoader.displayImage(SysConfig.PicUrl+jsonObject.getString("pic"),iv_bg,options);
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        Intent intent = new Intent();
                        intent.putExtra("routeID", jsonObject.getString("routeID"));
                        intent.setClass(getContext(), RouteDetailActivity.class);
                        getActivity().startActivity(intent);
                    }
                    catch(Exception ex){

                    }
                }
            });
            llBanner2.addView(layout);
        }
        catch(Exception ex){

        }
    }

    @Override
    public void setAction() {
        super.setAction();
        tv_more.setOnClickListener(this);
        ivEmail.setOnClickListener(this);
        mIndexDynamicsItemsAdapter.setComentClickListener(new IndexDynamicsItemsAdapter.ComentClickListener() {
            @Override
            public void onItemClick(int position, ResDynamicsBean.ListBean data) {
                mPopCommentSent.showAtLocation(mView.findViewById(R.id.pop_need), Gravity.CENTER, 0, 0);
                mPopCommentSent.position = position;
                mPopCommentSent.data = data;
                mPopCommentSent.isShowing();
                KeyBoardTools.openKeybord(mPopCommentSent.etComments, mContext);

            }
        });
        mIndexDynamicsItemsAdapter.setOnDeleteClickListener(new IndexDynamicsItemsAdapter.OnDeleteClickListener() {
            @Override
            public void onItemClick(int position, ResDynamicsBean.ListBean data) {
                postDeleteDynamics(data, position);
            }
        });
        mIndexDynamicsItemsAdapter.setIPraiseClickListener(new IndexDynamicsItemsAdapter.IPraiseClickListener() {
            @Override
            public void onItemClick(int position, ResDynamicsBean.ListBean data) {
                postLikeArticle(position, data);
            }
        });
    }

    //立即报名
    public void postJoinTeam(String teamID) {
        KJHttp kjh = new KJHttp();
        KJStringParams params = new KJStringParams();
        String cmdPara = "{\"cmd\":\"29\",\"uid\":\""+ SysConfig.uid +"\",\"token\":\""+ SysConfig.token+"\",\"teamid\":\""+teamID +"\"}";
        params.put("sendMsg", cmdPara);
        window.ShowWindow();
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {
                try {
                    JSONObject jsonObject = new JSONObject(t);
                    //Toast.makeText(mContext, t, Toast.LENGTH_LONG).show();
                    int result = Integer.parseInt(jsonObject.getString("result"));
                    if (result >= 1) {

                        Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_LONG).show();
                    } else {
                        if (result == -2) {
                            AppTools.jumptoLogin(mBaseActivity);
                        }
                        Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_LONG).show();
                    }
                } catch (Exception ex) {
                    Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_LONG).show();

                }
                window.closeWindow();
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_LONG).show();
                window.closeWindow();
            }
        });


    }


    public void postDeleteDynamics(ResDynamicsBean.ListBean bean, final int position) {
        KJHttp kjh = new KJHttp();
        KJStringParams params = new KJStringParams();
        String cmdPara = new ReqSentDynamicsBean("18", SysConfig.uid, SysConfig.token, ReqSentDynamicsBean.TYPEID_DELETE, bean.articleid, bean.content, bean.pic,"","","","0").ToJsonString();
        params.put("sendMsg", cmdPara);
        window.ShowWindow();
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {
                Log.d(TAG, "onSuccess: " + t);
                try {
                    JSONObject jsonObject = new JSONObject(t);
                    //Toast.makeText(mContext, t, Toast.LENGTH_LONG).show();
                    int result = Integer.parseInt(jsonObject.getString("result"));
                    if (result >= 1) {
                        mIndexDynamicsItemsAdapter.removeDynamics(position);
                        Toast.makeText(mContext, "删除成功", Toast.LENGTH_LONG).show();
                    } else {
                        AppTools.jumptoLogin(mBaseActivity, result);
                        Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_LONG).show();
                    }
                } catch (Exception ex) {
                    Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_LONG).show();

                }
                window.closeWindow();
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_LONG).show();
                window.closeWindow();
            }
        });


    }


    //添加评论
    public void postAddCommentDynamics(final ResDynamicsBean.ListBean bean, final int position) {


        if (TextUtils.isEmpty(mPopCommentSent.etComments.getText())) {
            ToastTools.showShort(mContext, "评论内容不能为空");
        } else {


            KJHttp kjh = new KJHttp();
            KJStringParams params = new KJStringParams();
            String cmdPara = new ReqDynamicsCommentBean("25", SysConfig.uid, SysConfig.token, bean.articleid, mPopCommentSent.etComments.getText().toString()).ToJsonString();
            params.put("sendMsg", cmdPara);
            window.ShowWindow();
            kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
                @Override
                public void onSuccess(String t) {
                    Log.d(TAG, "onSuccess: " + t);
                    try {
                        JSONObject jsonObject = new JSONObject(t);
                        //Toast.makeText(mContext, t, Toast.LENGTH_LONG).show();
                        int result = Integer.parseInt(jsonObject.getString("result"));
                        if (result >= 1) {
                            String tempstr = mPopCommentSent.etComments.getText().toString();
                            bean.commentList.add(new ResDynamicsBean.CommentListBean(tempstr, SysConfig.userInfoJson.getString("nick")));
                            mPopCommentSent.etComments.setText("");
                            mIndexDynamicsItemsAdapter.notifyItemChanged(position, bean);
                        } else {
                            AppTools.jumptoLogin(mBaseActivity, result);
                            Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_LONG).show();
                        }
                    } catch (Exception ex) {
                        Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_LONG).show();

                    }
                    window.closeWindow();
                }

                @Override
                public void onFailure(Throwable t, int errorNo, String strMsg) {
                    Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_LONG).show();
                    window.closeWindow();
                }
            });

        }
    }

    public void postLikeArticle(final int position, final ResDynamicsBean.ListBean bean) {
        KJHttp kjh = new KJHttp();
        KJStringParams params = new KJStringParams();
        String cmdPara = new ReqsLikeTeacherBean("15", SysConfig.uid, SysConfig.token, bean.articleid, "article").ToJsonString();
        params.put("sendMsg", cmdPara);
        window.ShowWindow();
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {
                Log.d(TAG, "onSuccess: " + t);
                try {
                    JSONObject jsonObject = new JSONObject(t);
                    int result = Integer.parseInt(jsonObject.getString("result"));
                    if (result >= 1) {
                        bean.likeuser = AppTools.likeUsers(bean);
                        mIndexDynamicsItemsAdapter.notifyItemChanged(position, bean);
                    } else {
                        AppTools.jumptoLogin(mBaseActivity, result);
                        Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_LONG).show();
                    }
                } catch (Exception ex) {
                    Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_LONG).show();

                }
                window.closeWindow();
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_LONG).show();

                window.closeWindow();
            }
        });
    }
    @Override
    public void initView() {
        super.initView();
        initTitle(mView);
        window = new NetProgressWindowDialog(mBaseActivity);
      //  ivBack.setVisibility(View.GONE);
//        root = (PtrClassicFrameLayout) mView.findViewById(R.id.root);
//        root.disableWhenHorizontalMove(true);
        /*
        bannerView = (AutoScrollViewPager) mView.findViewById(R.id.bannerView);
        mTextLayout = (LinearLayout) mView.findViewById(R.id.layout_index_points);
        rvImages = (RecyclerView) mView.findViewById(R.id.rc_image);
        tv_Address = (TextView) mView.findViewById(R.id.tv_Address);

        tv_tellPhoe = (TextView) mView.findViewById(R.id.tv_tellPhoe);
        //tv_shcoolIntr = (TextView) mView.findViewById(R.id.tv_shcoolIntr);
        rvTeachShow = (RecyclerView) mView.findViewById(R.id.rv_teach_show);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvImages.setLayoutManager(linearLayoutManager);
        */
        tv_more = (TextView) mView.findViewById(R.id.tv_more);
        ivEmail = (ImageView) mView.findViewById(R.id.iv_email);
        initRefresh();


    }

    @Override
    public void setData() {
        super.setData();
//        getdata(-1);

    }
    @Override
    public void onResume() {
        super.onResume();
        getdata(-1);
        getArticleList();
    }

    private void initRefresh() {
    }


    /**
     * @param type 1 获取新数据  2 点赞数据
     */
    public void getdata(final int type) {
        KJHttp kjh = new KJHttp();
       KJStringParams params = new KJStringParams();
        final String cmdPara = "{\"cmd\":\"14\",\"uid\":\""+SysConfig.uid+"\",\"token\":\""+SysConfig.token +"\",\"logintype\":\"1\"}";
        params.put("sendMsg", cmdPara);
        window.ShowWindow();
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {

                Log.d(TAG, "onSuccess: " + t);
                try {
                    JSONObject jsonObject = new JSONObject(t);

                    int result = Integer.parseInt(jsonObject.getString("result"));
                   if (result >= 1) {
                       JSONArray jsonArr = jsonObject.getJSONArray("bannerList");
                       JSONArray routeJsonArr = jsonObject.getJSONArray("routeList");
                       JSONArray teamJsonArr = jsonObject.getJSONArray("recommemdTeamList");
                       initViewPager(jsonArr);
                       initRecommendRoute(routeJsonArr);
                       initRecommendTeam(teamJsonArr);

//                        resHomeData = new Gson().fromJson(t, ResHomeData.class);
//                        switch (type) {
//                            case -1:
//                               // setPostData();
//                                break;
//                            default:
//                               // resHomeData.getTopTeachers().get(type);
//
//                                break;
//                        }
//
                   } else {
                        if (result == -2) {
                            AppTools.jumptoLogin(mBaseActivity);
                        }
                        else {
                            Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_SHORT).show();
                        }
                    }
                } catch (Exception ex) {
                   window.closeWindow();
                    Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_SHORT).show();
                }
                window.closeWindow();
            }

            @Override
           public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_SHORT).show();

               window.closeWindow();
            }
       });
    }


    public void getArticleList() {
        KJHttp kjh = new KJHttp();
        KJStringParams params = new KJStringParams();
        final String cmdPara = "{\"cmd\":\"17\",\"uid\":\""+SysConfig.uid+"\",\"token\":\""+SysConfig.token +"\",\"pagesize\":\"10\",\"pageno\":\"1\",\"routeid\":\"0\",\"teamid\":\"0\",\"touid\":\"0\"}";
        params.put("sendMsg", cmdPara);
        window.ShowWindow();
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {


                try {
                    JSONObject jsonObject = new JSONObject(t);
                    int result = Integer.parseInt(jsonObject.getString("result"));
                    if (result >= 1) {
                            ResDynamicsBean temp = new Gson().fromJson(t, ResDynamicsBean.class);
                            List<ResDynamicsBean.ListBean> bean = new ArrayList<ResDynamicsBean.ListBean>();

                            bean.addAll(AppTools.getDynamicsItemBean(temp));
                            mIndexDynamicsItemsAdapter.setDatas(bean);



//                        resHomeData = new Gson().fromJson(t, ResHomeData.class);
//                        switch (type) {
//                            case -1:
//                               // setPostData();
//                                break;
//                            default:
//                               // resHomeData.getTopTeachers().get(type);
//
//                                break;
//                        }
//
                    } else {
                        if (result == -2) {
                            AppTools.jumptoLogin(mBaseActivity);
                        }
                        else {
                            Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_SHORT).show();
                        }
                    }
                } catch (Exception ex) {
                    window.closeWindow();
                    Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_SHORT).show();
                }
                window.closeWindow();
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_SHORT).show();

                window.closeWindow();
            }
        });
    }


    /*
    private void setPostData() {
        if (resHomeData.getTopNews() != null && resHomeData.getTopNews().size() > 0) {
            ArrayList<ResHomeData.TopNewsBean> imgList = (ArrayList<ResHomeData.TopNewsBean>) resHomeData.getTopNews();

            if ((null != imgList) && (imgList.size() > 0)) {
//                KindergardenImageTextAdapter adapter = new KindergardenImageTextAdapter(
//                        this);
//                adapter.setDatas(imgList);
//                bannerView.setAdapter(adapter);
//                bannerView.setPageMargin(0);
//                bannerView.setInterval(1500);
//                bannerView.startAutoScroll();
            }
        }

    }
    */

    public void postLikeTeacher(final ResHomeData.TopTeachersBean teacher, final int position) {
        KJHttp kjh = new KJHttp();
        KJStringParams params = new KJStringParams();
        String cmdPara = new ReqsLikeTeacherBean("15", SysConfig.uid, SysConfig.token, teacher.getUser_id(), "user").ToJsonString();
        params.put("sendMsg", cmdPara);
        window.ShowWindow();
        kjh.urlGet(SysConfig.ServerUrl, params, new StringCallBack() {
            @Override
            public void onSuccess(String t) {

                //Log.d(TAG, "onSuccess: " + t);
                try {
                    JSONObject jsonObject = new JSONObject(t);
                    //Toast.makeText(mContext, t, Toast.LENGTH_LONG).show();
                    int result = Integer.parseInt(jsonObject.getString("result"));
                    if (result >= 1) {
                        getdata(position);
                    } else {
                        if (result == -2) {
                            AppTools.jumptoLogin(mBaseActivity, result);
                        }
                        Toast.makeText(mContext, jsonObject.get("retmsg").toString(), Toast.LENGTH_LONG).show();
                    }
                } catch (Exception ex) {
                    Toast.makeText(mContext, "数据请求失败", Toast.LENGTH_LONG).show();
                    window.closeWindow();
                }
                window.closeWindow();
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Toast.makeText(mContext, "网络异常，请稍后再试", Toast.LENGTH_LONG).show();
                window.closeWindow();
            }
        });
    }


}
